<template>
  <div>
     本数据来自时光网，之后会跳转到时光网
    <van-tabs v-model="activeName" sticky>
      <van-tab title="最新" name="a">
        <van-pull-refresh
          v-model="isLoading"
          success-text="刷新成功"
          @refresh="refresh"
        >
          <div v-for="item in news" :key="item.key" v-lazy="item">
            <newscard
              :title="item.title"
              :image="item.imgSrc"
              :newsSrc="item.newsSrc"
              :time="item.createTime"
            ></newscard>
          </div>
        </van-pull-refresh>
      </van-tab>
      <van-tab title="电视" name="b">
        <div v-for="item in newsTV" :key="item.key" v-lazy="item">
          <newscard
            :title="item.title"
            :image="item.imgSrc"
              :time="item.createTime"
            :newsSrc="item.newsSrc"
          ></newscard>
        </div>
      </van-tab>
      <van-tab title="电影" name="c">
        <div v-for="item in newsMusic" :key="item.key" v-lazy="item">
          <newscard
            :title="item.title"
            :image="item.imgSrc"
              :time="item.createTime"
            :newsSrc="item.newsSrc"
          ></newscard>
        </div>
      </van-tab>
      <van-tab title="人物" name="d">
        <div v-for="item in newsIndustry" :key="item.key" v-lazy="item">
          <newscard
            :title="item.title"
            :image="item.imgSrc"
              :time="item.createTime"
            :newsSrc="item.newsSrc"
          ></newscard>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { Search, Toast } from "vant";
import axios from "axios";
import qs from "../../node_modules/qs";
import newscard from "../components/newsCard";
export default {
  components: {
    newscard,
  },
  data() {
    return {
      news: {
        title: "",
        image: "",
      },
      newsTV: {
        title: "",
        image: "",
      },
      newsIndustry: {
        title: "",
        image: "",
      },
      newsMusic: {
        title: "",
        image: "",
      },
      activeName: "a",

      content: "金鹰节闭幕",
      count: 0,
      isLoading: false,
    };
  },
  created() {
    this.getLatest();
    this.getTV();
    this.getIndustry();
    this.getMusic();
  },
  methods: {
    getLatest() {
      axios.get("http://localhost:8888/newsLatest").then((res) => {
        // console.log(res.data)
        this.news = res.data;
      });
    },
    refresh() {
      this.getLatest();
      Toast("刷新成功");
    },
    getTV() {
      axios.get("http://localhost:8888/newsTV").then((res) => {
        // console.log(res.data)
        this.newsTV = res.data;
      });
    },
    getIndustry() {
      axios.get("http://localhost:8888/newsIndustry").then((res) => {
        console.log(res.data);
        this.newsIndustry = res.data;
        console.log(this.newsIndustry);
      });
    },
    getMusic() {
      axios.get("http://localhost:8888/newsMusic").then((res) => {
        // console.log(res.data)
        this.newsMusic = res.data;
      });
    },
  },
};
</script>

<style></style>
